package cn.wolfcode.domain;

import com.alibaba.fastjson.JSON;
import lombok.Getter;
import lombok.Setter;
import org.springframework.format.annotation.DateTimeFormat;

import java.util.Date;
import java.util.HashMap;

@Setter
@Getter
public class CourseOrder {
    private Long id;

    @DateTimeFormat(pattern = "yyyy-MM-dd")
    private Date inputTime;//购买时间

    private Customer customer;//客户

    private SystemDictionaryItem course;//购买课程

    private Long money;//购买金额

    //返回 json格式的字符串
    public String getJson() {
        //为了避免传一个department对象造成死循环,现在穿一个map对象
        HashMap<Object, Object> map = new HashMap<>();
        map.put("id", id);
        map.put("money", money);
        if (customer != null) {
            map.put("customerId", customer.getId());
            map.put("customerName", customer.getName());
        }
        if (course != null) {
            map.put("courseId", course.getId());
            map.put("courseName", course.getTitle());
        }

        return JSON.toJSONString(map);
    }

}